﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Xml.Serialization;
using Kiva7.DataRequests;

namespace Kiva7.DataClasses
{
    public class Partner
    {
        [XmlElement("id")]
        public int Id { get; set; }

        [XmlElement("name")]
        public string Name { get; set; }

        [XmlElement("status")]
        public string Status { get; set; }

        [XmlElement("Rating")]
        public string Rating { get; set; }

        [XmlElement("image")]
        public Image Image { get; set; }

        [XmlElement("start_date")]
        public DateTime? StartDate { get; set; }

        // todo

        [XmlElement("delinquency_rate")]
        public string DelinquencyRate { get; set; }

        [XmlElement("default_rate")]
        public string DefaultRate { get; set; }

        [XmlElement("total_amount_raised")]
        public string TotalAmountRaised { get; set; }

        [XmlIgnore]
        public double? DelinquencyRateUI
        {
            get
            {
                if (DelinquencyRate == @"N/A")
                {
                    return null;
                }
                double i;
                if (double.TryParse(DelinquencyRate, NumberStyles.Any, CultureInfo.InvariantCulture, out i))
                {
                    return i;
                }
                return null;
            }
        }

        [XmlIgnore]
        public double? DefaultRateUI
        {
            get
            {
                if (DefaultRate == @"N/A")
                {
                    return null;
                }
                double i;
                if (double.TryParse(DefaultRate, NumberStyles.Any, CultureInfo.InvariantCulture, out i))
                {
                    return i;
                }
                return null;
            }
        }

        [XmlIgnore]
        public double? TotalAmountRaisedUI
        {
            get
            {
                if (TotalAmountRaised == @"N/A")
                {
                    return null;
                }
                double i;
                if (double.TryParse(TotalAmountRaised, NumberStyles.Any, CultureInfo.InvariantCulture, out i))
                {
                    return i;
                }
                return null;
            }
        }

        [XmlElement("loans_posted")]
        public int LoansPosted { get; set; }
    }
}
